<template>
  <div class="groupdetial">
    <div class="infoarea">
      <div class="roomInfo">
        <div class="pic">
          <img
            src="../../../../../../assets/avatar1.svg"
            alt=""
          >
        </div>
        <div class="name">{{room.name}}</div>

      </div>
      <div class="main-info">

        <el-descriptions
          :column="4"
          border
        >
          <el-descriptions-item
            label="群简介"
            :span="4"
          > {{room.info}}</el-descriptions-item>
          <el-descriptions-item
            label="群号"
            :span="2"
          >{{room.number}}</el-descriptions-item>
          <el-descriptions-item
            label="创建时间"
            span="2"
          >
            {{$formatDate2(room.comment)}}
          </el-descriptions-item>

          <el-descriptions-item
            label="群主"
            :span="4"
          >
            <div class="groupOwner">
              {{room.author_name}}
            </div>
          </el-descriptions-item>
        </el-descriptions>

      </div>
      <!-- 按钮区域 -->
      <div
        class="btnarea"
        v-if="room.user_id != user_id"
      >
        <el-button
          type="danger"
          @click="leaveRoom"
          :disabled='room.user_id == null'
        >退出此群</el-button>
      </div>
      <div
        class="btnarea"
        v-else
      >
        <el-button
          type="danger"
          @click="deleteRoom"
        >解散群聊</el-button>
      </div>
    </div>
  </div>
</template>
 
 <script>
import { deleteRoomAPI, leaveMyRoomAPI } from "@/api/socket";
export default {
  data() {
    return {
      user_id: this.$store.state.users.userInfo.id,
    };
  },
  props: ["room"],
  methods: {
    async deleteRoom() {
      console.log("测试一下解散的room信息", this.room);
      const res = await deleteRoomAPI(this.room.id);

      if (res.status == 0) {
        this.$message.success("解散成功！");
        // this.$router.push("/my/chat/info");
        this.$bus.$emit("initCurrentUsesList");
        this.$store.dispatch("getMyRoomList");
        this.$store.dispatch("initCurrentRoomInfo", {});
        this.$socket.emit("deleteRoom", this.room.id, this.room.name);
      }
    },
    async leaveRoom() {
      const res = await leaveMyRoomAPI(this.room.id);
      console.log("点击了点击了点击了");
      console.log("---", res);
      if (res.status == 0) {
        this.$message.success("退出成功！");
        this.$socket.emit("leaveRoom", this.room.id);
        this.$store.dispatch("getMyRoomList");
        this.$store.dispatch("initCurrentRoomInfo", {});
        this.$bus.$emit("initCurrentUsesList");
      }
    },
  },
  mounted() {
    console.log(this.room);
  },
};
</script>
<style scoped lang='less'>
.groupdetial {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  flex-direction: column;
  .infoarea {
    width: 100%;
    height: 80%;
    justify-content: center;
    .roomInfo {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      padding: 14px;
      .pic {
        width: 200px;
      }
    }
    .main-info {
      display: flex;
      justify-content: center;
    }
    .btnarea {
      display: flex;
      width: 100%;
      justify-content: center;
      margin-top: 20px;
    }
  }
}
</style>